package com.shuai.common.constant;

public enum ChartAnalysisStatus {
    SUBMITTED(0, "已提交"),
    PROCESSING(1, "处理中"),
    SUCCESS(2, "处理成功"),
    FAILURE(3, "处理失败");

    private final int code;
    private final String description;

    ChartAnalysisStatus(int code, String description) {
        this.code = code;
        this.description = description;
    }

    public int getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据状态码获取枚举实例
     *
     * @param code 状态码
     * @return 枚举实例
     * @throws IllegalArgumentException 如果状态码对应的枚举不存在
     */
    public static ChartAnalysisStatus fromCode(int code) {
        for (ChartAnalysisStatus status : ChartAnalysisStatus.values()) {
            if (status.getCode() == code) {
                return status;
            }
        }
        throw new IllegalArgumentException("Invalid ChartAnalysisStatus code: " + code);
    }
}
